package com.atguigu.gmall.product.api;

import com.atguigu.gmall.model.product.BaseCategoryView;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.product.SpuSaleAttr;
import com.atguigu.gmall.product.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @ author     ：廖传港
 * @ date       ：Created in 2020/12/24 16:13
 * @ description：前台接口
 * @ modified By：
 * @ ersion:
 */
@Api(description = "前台商品api接口")
@RequestMapping("/api/product")
@RestController
public class ProductApiController {

    @Autowired
    private ProductService productService;

    @ApiOperation("查询三级分类")
    @GetMapping("/inner/getBaseCategoryView/{category3Id}")
    public BaseCategoryView getBaseCategoryView(@PathVariable Long category3Id) {
        return productService.getBaseCategoryView(category3Id);
    }

    @ApiOperation("获取sku基本信息与图片信息")
    @GetMapping("getSkuInfo/{skuId}")
    public SkuInfo getSkuInfo(@PathVariable Long skuId){
        return productService.getSkuInfo(skuId);
    }

    @ApiOperation("获取价格信息")
    @GetMapping("inner/getSkuPrice/{skuId}")
    public BigDecimal getSkuPrice(@PathVariable Long skuId){
        BigDecimal bigDecimal = productService.getSkuPrice(skuId);
        return bigDecimal;
    }


    @ApiOperation("商品详情之查询销售属性及选中")
    @GetMapping("inner/getSpuSaleAttrAndChecked/{spuId}/{skuId}")
    public List<SpuSaleAttr> getSpuSaleAttrAndChecked(@PathVariable Long spuId,
                                                      @PathVariable Long skuId){
        List<SpuSaleAttr> spuSaleAttrList  = productService.getSpuSaleAttrAndChecked(spuId,skuId);
        return spuSaleAttrList;
    }

    @ApiOperation("通过SPU查询基本属性值")
    @GetMapping("inner/getSaleAttrValuesBySpu/{spuId}/")
    public Map getSaleAttrValuesBySpu(@PathVariable Long spuId){
        Map<String,String> saleAttrValuesBySpuMap  = productService.getSaleAttrValuesBySpu(spuId);
        return saleAttrValuesBySpuMap;
    }

    @ApiOperation("查询所有分类视图对象集合")
    @GetMapping("inner/getBaseCategoryViewList")
    public List<BaseCategoryView> getBaseCategoryViewList(){
        return productService.getBaseCategoryViewList();
    }

}
